package edu.umd.fosite.geom;

public class Tree {

	public Vec direction;
	public Tree[] parts;

	public Tree(Vec dir) {
		direction = dir;
		parts = new Tree[] {};
	}

	public Tree(Vec dir, Tree[] ps) {
		direction = dir;
		parts = ps;
	}

	public static Tree generateVertical(int levels, int branching, double z,
			double r, double zshrink, double rshrink) {
		return new Tree(new Vec(0, 0, 1), generateVertical_(levels, branching,
				z, r, zshrink, rshrink));
	}

	private static Tree[] generateVertical_(int level, int branching, double z,
			double r, double zshrink, double rshrink) {
		if (level < 1)
			return new Tree[] {};

		Tree[] ret = new Tree[branching];
		for (int i = 0; i < branching; i++) {
			double a = (double) i / branching * 2 * Math.PI;
			ret[i] = new Tree(new Vec(r * Math.cos(a), r * Math.sin(a), z),
					generateVertical_(level - 1, branching, z * zshrink, r
							* rshrink, zshrink, rshrink));
		}
		return ret;
	}
}
